<?php
session_start();
$index = 1;
ini_set('display_errors', 1);

if(!isset($_SESSION['leider']))
{
    $_SESSION['leider'] = false;
}
if(!isset($_SESSION['admin']))
{
    $_SESSION['admin'] = 0;
}

require_once('config/database.php');
require_once('config/settings.php');

function __autoload($class) {
    require_once("classes/$class.class.php");
}

if(isset($_POST['btnInloggen']))
{
    $login = new Login($_POST['loginUsername'], $_POST['loginPassword']);
    if($login->check_loggedin())
    {
        $_SESSION['login'] = $login->get_username();
        $_SESSION['loginid'] = $login->get_id();
        $_SESSION['leider'] = $login->get_leider();
        $_SESSION['admin'] = $login->get_admin();
        $_SESSION['beheerder'] = $login->get_beheerder();
    }
}

class Main {
    public static function get_page() {
        if(isset($_GET['p']))
            $page = $_GET['p'];
        else
            $page = "/";
        if($page == "logout")
        {
            session_destroy();
            echo("<meta http-equiv='refresh' content='0;url=index.php?p=home'>");
            return "pages/home.php";
        }
        if(!(strpos($page, "/")) && !(strpos($page, ".")) && $page)
        {
            $path = "pages/$page.php";
            if(file_exists($path))
            {
                return $path;
            }
            else if ($page == "/")
            {
                return "pages/home.php";
            }
            else
            {
                return("pages/404.php");
            }
        }
    }
}
?>